<?php

declare(strict_types=1);
/**
 * This file is part of habo_new_media.
 *
 * @link     https://www.berlen.cn/
 * @contact  tech@berlen.cn
 * @license  http://gitlab.rehou.cn/habo/habo_new_media/-/blob/master/README.md
 */
namespace app\controller;

use app\BaseController;
use app\enum\CodeEnum;
use app\service\fetch\KuaiShouFetchService;
use think\response\Json;

class KsFetchController extends BaseController
{
    /**
     * 拉取应用.
     * @deprecated
     */
    public function fetchAppList(): Json
    {
        $advertiserId = request()->post('advertiser_id');
        if (! $advertiserId) {
            return self::outputFail(CodeEnum::BUSINESS_ERROR, '账户id不能为空');
        }
        $res = KuaiShouFetchService::fetchAppList($advertiserId);
        KuaiShouFetchService::fetchAppSubPackage($advertiserId);
        if ($res) {
            return self::outputSuccess();
        }
        return self::outputFail(CodeEnum::BUSINESS_ERROR, KuaiShouFetchService::getError(0));
    }

    /**
     * 拉取定向模板.
     * @deprecated
     */
    public function fetchTargetTemplate(): Json
    {
        $advertiserId = request()->post('advertiser_id');
        if (! $advertiserId) {
            return self::outputFail(CodeEnum::BUSINESS_ERROR, '账户id不能为空');
        }
        $res = KuaiShouFetchService::fetchTargetTemplate($advertiserId);
        if ($res) {
            return self::outputSuccess();
        }
        return self::outputFail(CodeEnum::BUSINESS_ERROR, KuaiShouFetchService::getError(0));
    }
}
